﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Iris.Engine;
using System.Diagnostics;

namespace Iris.UI
{
    /// <summary>
    /// Logique d'interaction pour Vignette.xaml
    /// </summary>
    public partial class Vignette : UserControl
    {
        public ImageSort Image { get; set; }

        public static Vignette Create(ImageSort image){
            return new Vignette(image) { Margin = new Thickness(1) };
        }

        protected Vignette(ImageSort image)
        {
            
            InitializeComponent();
            Image = image;
            Apercu.Source = image.thumbail;
            Update();
        }

        public void Update() {

            Score.Content = String.Format("{0:0}", Image.Score);
            CheckBox.IsChecked = !Image.IsBlamed;

            Etoile1.Visibility = Image.Rating > 0 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            Etoile2.Visibility = Image.Rating > 12 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            Etoile3.Visibility = Image.Rating > 38 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            Etoile4.Visibility = Image.Rating > 63 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            Etoile5.Visibility = Image.Rating > 88 ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Process.Start(new ProcessStartInfo("explorer", Image.DataSource.FullName));
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckBox.IsChecked == true)
            {
                SortCore.singleton.BlameImage(Image);
            }
            else {
                SortCore.singleton.ActivateImage(Image);
            }
        }
    }
}
